package com.me.batm.screens;

import aurelienribon.tweenengine.Tween;
import aurelienribon.tweenengine.TweenManager;
import aurelienribon.tweenengine.equations.Bounce;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Rectangle;
import com.me.batm.GameConstants;
import com.me.batm.OurGdxGame;

public class SplashScreen implements Screen{

	private OurGdxGame ourGdxGame;
	private SpriteBatch spriteBatch;
	private Texture splsh;
	private long timerInit;
    private static long splashDuration = 3000;
    TweenManager manager;
    Rectangle rec;
	public SplashScreen(OurGdxGame ourGdxGame) {
		// TODO Auto-generated constructor stub
		this.ourGdxGame = ourGdxGame;
		timerInit = System.currentTimeMillis();
		manager = new TweenManager();
		rec = new Rectangle(0, 0, GameConstants.DESKTOP_SCREEN_WIDTH, GameConstants.DESKTOP_SCREEN_HEIGHT);
	}

	@Override
	public void render(float delta) {
		// TODO Auto-generated method stub
		 Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
         spriteBatch.begin();
         spriteBatch.draw(splsh, 0, 0, GameConstants.SCREEN_WIDTH, GameConstants.DESKTOP_SCREEN_HEIGHT);
         spriteBatch.end();
         if(System.currentTimeMillis() - timerInit > splashDuration) {
        	 ourGdxGame.setScreen(new MenuScreen(SplashScreen.this.ourGdxGame));
         }
		Tween.to(rec, 1, 1f)
		.target(0)
		.ease(Bounce.INOUT)
		.start(manager);
		manager.update(delta);
	}

	@Override
	public void resize(int width, int height) {
		// TODO Auto-generated method stub		
	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		spriteBatch = new SpriteBatch();
        splsh = new Texture(Gdx.files.internal("data/truestory.png"));
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub		
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}

}
